//
//  ISCallSwitchCollectionViewCell.m
//  iPhoneSafety
//
//  Created by dlon 2018/12/31.
//  Copyright © 2018年 com.li.ding. All rights reserved.
//

#import "ISCallSwitchCollectionViewCell.h"
#import "NWLazyProperty.h"
#import <Masonry/Masonry.h>
#import "UIColor+NWHex.h"

@implementation ISCallSwitchCollectionViewCell


- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self.contentView addSubview:self.titleLabel];
        [self.contentView addSubview:self.switchView];
        
        [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(self.contentView);
            make.left.equalTo(self.contentView).offset(17.f);
        }];
        
        [self.switchView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(self.contentView);
            make.right.equalTo(self.contentView).offset(-18.f);
        }];
        
    }
    return self;
}


- (void)changge {
    if (self.actionBlock) {
        self.actionBlock(self.switchView.isOn);
    }
}

#pragma mark - set & get
NWLazyPropertyWithInit(UISwitch, switchView, {
    _switchView.onTintColor = [UIColor nw_colorWithHex:0x0084FF];
    _switchView.tintColor = [UIColor nw_colorWithHex:0xCDD8E2];
    _switchView.backgroundColor = [UIColor nw_colorWithHex:0xCDD8E2];
    _switchView.clipsToBounds = YES;
    _switchView.layer.cornerRadius = CGRectGetHeight(_switchView.frame)/2.f;

    [_switchView addTarget:self action:@selector(changge) forControlEvents:UIControlEventValueChanged];
})

NWLazyPropertyWithInit(UILabel, titleLabel, {
    _titleLabel.font = [UIFont systemFontOfSize:17.f];
    _titleLabel.textColor = [UIColor nw_colorWithHex:0x222222];
})


@end
